package cn.jiyun.controller;

import cn.jiyun.pojo.Xxb;
import cn.jiyun.service.FileOssService;
import cn.jiyun.service.XxbService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/xxb")
public class XxbController {
    @Autowired
    XxbService xxbService;
    @Autowired
    FileOssService fileOssService;
    @RequestMapping("/findall")
    public PageInfo<Xxb> findall(@RequestBody Xxb xxb,
                                 @RequestParam(name = "page",defaultValue = "1")Integer page,
                                 @RequestParam(name = "size",defaultValue = "5")Integer size){
        return xxbService.findall(xxb, page, size);
    }
    @RequestMapping("/add")
    public Xxb add(@RequestBody Xxb xxb){
        if (xxb.getId()==null){
            xxb.setPid(1);
            return xxbService.add(xxb);
        }else {
            return xxbService.updatexg(xxb);
        }
    }
    @RequestMapping("/tp")
    public String tp(@RequestPart("file") MultipartFile file){
        return fileOssService.uploadToOss(file);
    }
    @RequestMapping("/update")
    public Xxb update(@RequestParam("id") Integer id){
        return xxbService.update(id);
    }
    @RequestMapping("/delete")
    public Xxb delete(@RequestParam("id") Integer id){
        return xxbService.delete(id);
    }
    @RequestMapping("/find")
    public List<Xxb> find(){
        return xxbService.find();
    }
    @RequestMapping("/hf")
    public Xxb hf(@RequestParam("id") Integer id){
     return xxbService.hf(id);
    }
    @RequestMapping("/hfss")
    public Integer hfss(@RequestParam("id") Integer id){
     return xxbService.hfss(id);
    }
}